package com.carsystem.controller;


import com.carsystem.entity.CarBrandAndCar;
import com.carsystem.entity.Carbrand;
import com.carsystem.service.ICarbrandService;
import com.carsystem.utils.MessageConstant;
import com.carsystem.utils.PageResult;
import com.carsystem.utils.QueryPageBean;
import com.carsystem.utils.Result;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ykl
 * @since 2021-12-04
 */
@RestController
@RequestMapping("/carbrand")
public class CarbrandController {

    @Reference
    private ICarbrandService carbrandService;

    /**
     * 汽车品牌分页查询
     * @param queryPageBean
     * @return
     */
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        return carbrandService.findPage(queryPageBean);
    }

    /**
     * 添加汽车品牌
     * @param carbrand
     * @param carIds
     * @return
     */
    @PostMapping("/saveCarBrand")
    public Result saveCarBrand(@RequestBody Carbrand carbrand, int[] carIds){
        return carbrandService.saveCarBrand(carbrand,carIds);
    }

    /**
     * 删除汽车品牌
     * @param id
     * @return
     */
    @RequestMapping("/deleteCarBrand")
    public Result deleteCarBrand(int id){
        return carbrandService.deleteCarBrand(id);
    }

    /**
     * 更新汽车品牌
     * @param carbrand
     * @param carIds
     * @return
     */
    @RequestMapping("/updateCarBrand")
    public Result updateCarBrand(@RequestBody Carbrand carbrand,int[] carIds){
        return carbrandService.updateCarBrand(carbrand,carIds);
    }

    /**
     * 根据id查询汽车品牌、汽车id集合
     * @param id
     * @return
     */
    @RequestMapping("/{id}")
    public Result getCarBrandAndCarById(@PathVariable int id){
        CarBrandAndCar carBrandAndCarById = carbrandService.getCarBrandAndCarById(id);
        return new Result(true, MessageConstant.QUERY_CARBRAND_SUCCESS,carBrandAndCarById);
    }

    /**
     * 查询所有的汽车品牌
     * @return
     */
    @RequestMapping("/findAllCarbrand")
    public Result findAllCarbrand(){
        return carbrandService.findAllCarbrand();
    }

}

